package base;

/**
 * @author 何昌杰
 */
public class Base16 {

    /**
     * 二叉树的镜像
     * 请完成一个函数，输入一个二叉树，该函数输出它的镜像。
     *
     * 示例 1：
     *
     * 输入：root = [4,2,7,1,3,6,9]
     * 输出：[4,7,2,9,6,3,1]
     *
     * 限制：
     * 0 <= 节点个数 <= 1000
     *
     */
    public static void main(String[] args) {
        TreeNode A = new TreeNode(1);
        A.left = new TreeNode(2);
        A.left.left = new TreeNode(3);
        A.left.right = new TreeNode(4);
        A.right = new TreeNode(2);
        A.right.left = new TreeNode(4);
        A.right.right = new TreeNode(3);

        System.out.println(isSymmetric(A));
    }

    public static boolean isSymmetric(TreeNode root) {
        return root == null || recur(root.left, root.right);
    }

    public static boolean recur(TreeNode left, TreeNode right) {
        if(left == null && right == null){
            return true;
        }
        if(left == null || right == null || left.val != right.val){
            return false;
        }
        return recur(left.left, right.right) && recur(left.right, right.left);
    }

}
